package com.cy.pj.goods.util;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)//链式
//    @JsonInclude:包含 不为NULL

public class R<T> implements Serializable {

    private Integer state;

    private String message;


    private T data;

    public static R ok(){
        return new R().setState(R.State.OK);
    }
    public static <T> R<T> ok(T data){
        return R.ok().setData(data);
    }

    public static R failure(Integer state,String message){
        return new R().setState(state).setMessage(message);
    }

    public static R failure(Integer state,Throwable e){
        return failure(state,e.getMessage());
    }

    public interface State{
        Integer OK=2000;
        Integer ERR_INVITE_CODE=4000;
        Integer ERR_CLASS_DISABLED=4010;
        Integer ERR_PHONE_DUPLICATE=4020;
        Integer ERR_INSERT=4030;
        Integer ERR_INVALID_PARAMETER=4040;
        Integer ERR_FILE_EMPTY=4050;
        Integer ERR_FILE_SIZE=4060;
        Integer ERR_FILE_TYPE=4070;
        Integer ERR_FILE_STATE=4080;
        Integer ERR_FILE_UPLOAD_IO=4090;
        Integer ERR_QUESTION_NOT_FOUND=4100;
        Integer ERR_ANSWER_NOT_FOUND=4110;


    }

}

